$(function () {
    //获取过滤的文件类型
    //params aFileTypes array
    //return strign
//    function getFileType(aFileTypes) {
//        if (aFileTypes === void 0) { aFileTypes = ['jpg', 'png', 'gif', 'bmp', 'jpeg']; }
//        var sFilesType = '';
//        if (aFileTypes.length == 0)
//            return '*.*';
//        aFileTypes.forEach(function (i) {
//            sFilesType += '*.' + i + ', *.' + i.toString().toUpperCase() + ',';
//        });
//        return sFilesType.replace(/,$/, '');
//    }
//    var swfUploadConfig = {
//        upload_url: '',
//        flash_url: base + '/resource/plug/swfupload/dist/swfupload.swf',
//        file_post_name: 'hyh',
//        file_types: getFileType(),
//        prevent_swf_caching: false,
//        file_upload_limit: 5,
//        file_size_limit: '5M',
//        button_placeholder_id: 'swfupload',
//        button_image_url: base + '/resource/images/swfupload-btn.png',
//        button_width: '73',
//        button_height: '25',
//        button_cursor: -2
//    };
//    new SWFUpload(swfUploadConfig);
//    $('.upload-files .upload').on('mouseover', 'li', function () {
//        $(this).addClass('hover');
//    }).on('mouseout', 'li', function () {
//        $(this).removeClass('hover');
//    });
    var cS = '929 956 957'.split(' '), prov = $('#element_id').attr('prov');
    if (prov) {
        cS = prov.replace(/^,|,$/, '').split(',');
    }
    if (cS.length == 2)
        cS[2] = '';
    $('#element_id p:first').citySelect({
        url: base + '/resource/plug/citySelect/city.min.js',
        prov: cS[0],
        city: cS[1],
        dist: cS[2]
    });
    $('[name="stype"]').change(function(obj){
    	if(this.value == 'true'){
    		$('#refund_address').show();
    	}else{
    		$('#refund_address').hide();
    	}
    });
    //修改数量
    var hpStock = new NumberChange($('.hp-stock'));
    hpStock.config.min = 1;
    hpStock.addObserver(new CheckNum());
    $('#return-form').validate({
        rules: {
            stype: {
                required: true
            },
            describe: {
                required: true
            },
            address: {
                required: true
            },
            name: {
                required: true
            },
            phone: {
                required: true,
                phone: true
            }
        },
        messages: {
            stype: {
                required: '请选择相应的服务类型'
            },
            describe: {
                required: '请输入本商品出现的问题描述'
            },
            address: {
                required: '请输入详细的收货地址'
            },
            name: {
                required: '请输入联系人姓名'
            },
            phone: {
                required: '请输入联系号码'
            }
        },
        errorPlacement: function (error, element) {
            error.appendTo(element.parent().find('.err-msg').show());
        }
    });
});
var CheckNum = (function () {
    function CheckNum() {
    }
    CheckNum.prototype.update = function (num) {
    	var quantity = parseInt($("#quantity").val());
    	if(num > quantity || num <= 0){
    		$('.product-num .err-msg').show().html('您输入的退货商品数量错误!');
    	}else{
    		$('.cart-num').val(num);
    		$('.product-num .err-msg').show().html('');
    	}
    };
    return CheckNum;
})();
/**
 * 删除指定的图片
 * @param {string} sImgSrc 图片地址
 */
function delApplyUploadImg(sImgSrc, _this) {
    if (sImgSrc === void 0) { sImgSrc = ''; }
    if (_this === void 0) { _this = null; }
    if (sImgSrc.length == 0)
        return false;
    oDialog.confirm('您确定删除此图片?', function () {
        //TODO 异步请求删除地址
        //success
        $(_this).parents('li').remove();
    });
}

function beforeSubmit(){
    var quantity = parseInt($("#quantity").val());
    var cur = parseInt($("[name='quantity']").val());
    return cur <= quantity;
}
